package com.li.configure;

import com.li.filter.RocketMqSendMessageHook;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @program: rocketmq_boot
 * @description:
 * @author: li
 * @create: 2023-03-08 16:56
 **/
@Component
public class DefaultMQProducerBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof DefaultMQProducer) {
            DefaultMQProducer producer = (DefaultMQProducer) bean;
            // 设置钩子方法
            producer.getDefaultMQProducerImpl().registerSendMessageHook(new RocketMqSendMessageHook());
        }
        return bean;
    }
}
